package com.bigknow.appstore.proxy.entity;


import com.bigknow.appstore.proxy.enumerate.LogLevel;
import com.bigknow.appstore.proxy.enumerate.ProxyState;
import com.bigknow.appstore.proxy.enumerate.SecurityType;
import org.mongodb.morphia.annotations.Entity;
import org.mongodb.morphia.annotations.Id;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 用于存储proxy的基本信息
 * Created by chaos on 2016/9/8.
 */
@Entity("web.appstore.proxy.proxymeta")
public class ProxyMeta implements Serializable {

    @Id
    private String id;

    private String name;

    private int port;
    private boolean HTTPS;
    private boolean keepAlive;
    private int timeout;

    private int sndbuf;

    private int rcvbuf;

    private int backlog;

    /**
     * 是否开启同步连接模式,默认为false
     */
    private boolean syncModel = false;

    /**
     * 是否启用最后一次访问记录功能，主要是用于有些情况下
     * 采用了绝对路径导致访问无法获得正确的requestVo信息，
     * 这个时候可以通过同一个channel的上一次访问的request来得到。
     * 默认为true
     */
    private boolean useLastRequest = true;

    /**
     * last request 超时时间,useLastRequest=true 才生效,默认 30000毫秒
     */
    private int lastRequestTimeout = 30000;

    /**
     * 创建的时候或者重新启动服务的时候是否自动运行
     */
    private boolean runAuto;

    private ProxyState state;

    private Map<SecurityType, SecurityMeta> secMaps = new HashMap<>();

    /**
     * 日志级别
     */
    private LogLevel logLevel;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public boolean isKeepAlive() {
        return keepAlive;
    }

    public void setKeepAlive(boolean keepAlive) {
        this.keepAlive = keepAlive;
    }

    public int getTimeout() {
        return timeout;
    }

    public void setTimeout(int timeout) {
        this.timeout = timeout;
    }

    public int getSndbuf() {
        return sndbuf;
    }

    public void setSndbuf(int sndbuf) {
        this.sndbuf = sndbuf;
    }

    public int getRcvbuf() {
        return rcvbuf;
    }

    public void setRcvbuf(int rcvbuf) {
        this.rcvbuf = rcvbuf;
    }

    public int getBacklog() {
        return backlog;
    }

    public void setBacklog(int backlog) {
        this.backlog = backlog;
    }

    public boolean isHTTPS() {
        return HTTPS;
    }

    public void setHTTPS(boolean HTTPS) {
        this.HTTPS = HTTPS;
    }

    public boolean isRunAuto() {
        return runAuto;
    }

    public void setRunAuto(boolean runAuto) {
        this.runAuto = runAuto;
    }

    public ProxyState getState() {
        return state;
    }

    public void setState(ProxyState state) {
        this.state = state;
    }

    public LogLevel getLogLevel() {
        return logLevel;
    }

    public void setLogLevel(LogLevel logLevel) {
        this.logLevel = logLevel;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public boolean isSyncModel() {
        return syncModel;
    }

    public void setSyncModel(boolean syncModel) {
        this.syncModel = syncModel;
    }

    public boolean isUseLastRequest() {
        return useLastRequest;
    }

    public void setUseLastRequest(boolean useLastRequest) {
        this.useLastRequest = useLastRequest;
    }

    public int getLastRequestTimeout() {
        return lastRequestTimeout;
    }

    public void setLastRequestTimeout(int lastRequestTimeout) {
        this.lastRequestTimeout = lastRequestTimeout;
    }

    public Map<SecurityType, SecurityMeta> getSecMaps() {
        return secMaps;
    }

    public void setSecMaps(Map<SecurityType, SecurityMeta> secMaps) {
        this.secMaps = secMaps;
    }
}
